package com.sgb.kjwl.view.ui.adapter.self.packers;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;


import androidx.databinding.library.baseAdapters.BR;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.LayoutRecyclerFlowLayoutBinding;
import com.sgb.kjwl.model.entity.self.SelfTeamIntroduceEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class FlowLayoutAdapter1 extends BaseRecycleAdapter<SelfTeamIntroduceEntity.BusinessScopesBean> {

    private boolean isDelete;

    public FlowLayoutAdapter1(Context context, List<SelfTeamIntroduceEntity.BusinessScopesBean> datas) {
        super(context, R.layout.layout_recycler_flow_layout, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfTeamIntroduceEntity.BusinessScopesBean entity) {
        holder.setBinding(BR.viewModel, null);
        showEndWorkType(((LayoutRecyclerFlowLayoutBinding) holder.getmBinding()).tvType, entity);
        ((LayoutRecyclerFlowLayoutBinding) holder.getmBinding()).rlDelete.setVisibility(isDelete ? View.VISIBLE : View.GONE);
        ((LayoutRecyclerFlowLayoutBinding) holder.getmBinding()).rlDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isDelete()) {
                    getDatas().remove(holder.getAdapterPosition());
                    notifyDataSetChanged();
                }
            }
        });

    }

    private void showWorkType(TextView textView, SelfTeamIntroduceEntity.BusinessScopesBean entity) {
        StringBuilder sb = new StringBuilder();
        if (!TextUtils.isEmpty(entity.getFirstCategoryName())) {
            sb.append(entity.getFirstCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getSecondCategoryName())) {
            sb.append("/").append(entity.getSecondCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getThirdCategoryName())) {
            sb.append("/").append(entity.getThirdCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getFourCategoryName())) {
            sb.append("/").append(entity.getFourCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getFifthCategoryName())) {
            sb.append("/").append(entity.getFifthCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getSixthCategoryName())) {
            sb.append("/").append(entity.getSixthCategoryName());
        }
        textView.setText(sb.toString());
    }

    private void showEndWorkType(TextView textView, SelfTeamIntroduceEntity.BusinessScopesBean entity) {
        if (!TextUtils.isEmpty(entity.getSixthCategoryName())) {
            textView.setText(entity.getSixthCategoryName());
            return;
        }
        if (!TextUtils.isEmpty(entity.getFifthCategoryName())) {
            textView.setText(entity.getFifthCategoryName());
            return;
        }
        if (!TextUtils.isEmpty(entity.getFourCategoryName())) {
            textView.setText(entity.getFourCategoryName());
            return;
        }
        if (!TextUtils.isEmpty(entity.getThirdCategoryName())) {
            textView.setText(entity.getThirdCategoryName());
            return;
        }
        if (!TextUtils.isEmpty(entity.getSecondCategoryName())) {
            textView.setText(entity.getSecondCategoryName());
            return;
        }
        if (!TextUtils.isEmpty(entity.getFirstCategoryName())) {
            textView.setText(entity.getFirstCategoryName());
            return;
        }

    }

    public boolean isDelete() {
        return isDelete;
    }

    public void setDelete(boolean delete) {
        isDelete = delete;
        notifyDataSetChanged();
    }
}
